<%
layout("tabbar.html"){
%>
<div class="weui-cells__title">添加油卡</div>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <label class="weui-label">卡号</label>
        </div>
        <div class="weui-cell__bd">
            <input id="numberInput" class="weui-input" type="number" placeholder="请输入加油卡卡号" />
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <label class="weui-label">持卡人</label>
        </div>
        <div class="weui-cell__bd">
            <input id="usernameInput" class="weui-input" type="text" placeholder="请输入持卡人姓名" />
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <label class="weui-label">持卡人手机</label>
        </div>
        <div class="weui-cell__bd">
            <input id="phoneInput" class="weui-input" type="text" placeholder="请输入持卡人手机" />
        </div>
    </div>
    <div class="weui-cells__title">卡类型</div>
    <div class="weui-cells weui-cells_radio">
        <label class="weui-cell weui-check__label" for="ZSY">
            <div class="weui-cell__bd">
                <p>中石油</p>
            </div>
            <div class="weui-cell__ft">
                <input type="radio" class="weui-check" name="typeRadio" id="ZSY" value="ZSY" />
                <span class="weui-icon-checked"></span>
            </div>
        </label>

        <label class="weui-cell weui-check__label" for="ZSH">
            <div class="weui-cell__bd">
                <p>中石化</p>
            </div>
            <div class="weui-cell__ft">
                <input type="radio" class="weui-check" name="typeRadio" id="ZSH" value="ZSH"/>
                <span class="weui-icon-checked"></span>
            </div>
        </label>
    </div>
    <div class="weui-btn-area">
        <a href="javascript:" id="submitButton" class="weui-btn weui-btn_primary">确定</a>
    </div>
</div>
<script src="/js/net.js"></script>
<script>
    $('#submitButton').click(function() {
        var oilCard = {
            number: $('#numberInput').val(),
            username: $('#usernameInput').val(),
            type: $("input[name='typeRadio']:checked").val(),
            phone: $('#phoneInput').val()
        };
        net()
            .url('${ctxPath}/api/oilCards')
            .data(oilCard)
            .success(function (response) {
                if (response.code == 0) {
                    showToast();
                    window.history.back(-1);
                } else {
                    alert('添加失败，' + response.message);
                }
            })
            .error(function (err) {
                alert('网络错误');
            })
            .post();
    });
</script>
<% } %>